package com.logistics.flow.controller;


import com.logistics.erp.entity.model.ErpDirectSave;
import com.logistics.erp.entity.model.ErpStashSave;
import com.logistics.erp.entity.model.ErpTakeOverSave;
import com.logistics.flow.service.FlowService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 物料流向 前端控制器
 * </p>
 *
 * @author yunjian.ban
 * @since 2024-05-21
 */
@RestController
@RequestMapping("lgs/flow")
public class FlowController {

    @Autowired
    private FlowService flowService;

    /**
     * 查询物料单据信息
     *
     * @param code
     * @return
     */
    @GetMapping("/materialFlow/{code}")
    @LoggerListener(businessName = "流向处理-查询物料单据信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity materialFlow(@PathVariable("code") String code) throws MessageException {
        return ResponseUtil.success(flowService.materialFlow(code));
    }

    /**
     * 通过任务号进行直投处理
     *
     * @param erpDirectPut
     * @return
     */
    @PutMapping("/save")
    @LoggerListener(businessName = "通过任务号进行直投处理", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody ErpDirectSave erpDirectPut) throws MessageException {
        flowService.save(erpDirectPut);
        return ResponseUtil.success(true);
    }

    /**
     * 暂存
     *
     * @param erpStashSave
     * @return
     */
    @PostMapping("/stash")
    @LoggerListener(businessName = "暂存处理", methodName = LoggerMethod.SAVE)
    public ResponseEntity insertStash(@RequestBody ErpStashSave erpStashSave) {
        flowService.insertStash(erpStashSave);
        return ResponseUtil.success(true);
    }

    /**
     * 报工周转
     *
     * @param erpTakeOverSave
     * @return
     */
    @PostMapping("/takeOver")
    @LoggerListener(businessName = "报工周转处理", methodName = LoggerMethod.SAVE)
    public ResponseEntity insertStash(@RequestBody ErpTakeOverSave erpTakeOverSave) {
        flowService.insertTakeOver(erpTakeOverSave);
        return ResponseUtil.success(true);
    }

}

